package com.by.common.controller;

import com.by.common.entity.ResultBean;
import com.by.common.ex.ValidateException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLSyntaxErrorException;
/*
* 捕捉全局异常
* 用于给出各类异常提示方便处理
* */
@RestControllerAdvice //异常的增强注解
public class GlobalExceptionController extends BaseController {
//    处理验证异常
     @ExceptionHandler(ValidateException.class)
    public ResultBean handleException(ValidateException e) {
//         给出提示
        return fail("验证失败",e.getErrors());
     }
//     捕获sql语句异常
     @ExceptionHandler(SQLSyntaxErrorException.class)
    public ResultBean handleException(SQLSyntaxErrorException e) {
         return fail("sql语句错误!");
     }
//     莫名其妙的异常(暂时未找到原因)
     @ExceptionHandler(NumberFormatException.class)
    public void handleException(NumberFormatException e) {
         System.out.println("---------------");
     }
}
